package com.woniuxy.automotivemanagementsystem.controller;

import com.woniuxy.automotivemanagementsystem.entity.Car;
import com.woniuxy.automotivemanagementsystem.entity.vo.CarVo;
import com.woniuxy.automotivemanagementsystem.entity.vo.NewsVo;
import com.woniuxy.automotivemanagementsystem.service.CarService;
import com.woniuxy.automotivemanagementsystem.service.NewsService;
import com.woniuxy.automotivemanagementsystem.utils.IdDto;
import com.woniuxy.automotivemanagementsystem.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/car")
@CrossOrigin
public class CarController {
    @Autowired
    private CarService carService;
    /*
     * 所有汽车菜单中的条件查询所有方法
     * */
    @PostMapping("/queryCondition")
    public Result queryCondition(@RequestBody CarVo carFrom){
        return carService.queryCondition(carFrom);
    }
    /*
    *   汽车管理中的新增或修改接口
    * */
    @PutMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Car car){
        carService.saveOrUpdate(car);
        return Result.success(true);
    }
    /*
    *   汽车管理中的删除接口
    * */
    @PutMapping("/delete")
    public Result delete(@RequestBody IdDto idDto){
        carService.lambdaUpdate()
                .eq(Car::getCid,idDto.getId())
                .set(Car::getStatus,1)
                .update();
        return Result.success(true);
    }
}
